home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tpl60n19.zip / STRSOURC.ZIP / STRHDEL.ASM < prev    next >
Assembly Source File  |  1993-01-25  |  4KB  |  79 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 6.0        *
  5. ; *     String Deletion                                 *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1990-1993 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   STRHDEL
  12.  
  13.  
  14. CODE         SEGMENT BYTE PUBLIC
  15.  
  16.              ASSUME  CS:CODE
  17.  
  18. ; Publics
  19.  
  20.              PUBLIC  SDelete
  21.  
  22. ;-------------------------------------------------------------------------------
  23. ; Delete standard procedure: Delete (VAR S: STRING; Index, Count: INTEGER);
  24. ;
  25. ; Delete deletes Count characters in S, beginning at position Index. The
  26. ; algorithm determines if the characters are effectively deleted from the end
  27. ; of the string, in which case it simply sets the string length to Index-1. If
  28. ; characters are to be deleted from somewhere in the middle of the string, it
  29. ; calculates the number of characters in the string after the last deleted one
  30. ; and copies these characters to position Index, decrementing the string length
  31. ; by Count.
  32. ;
  33. ; On entry:  [SP+4]  Count
  34. ;            [SP+6]  Index
  35. ;            [SP+8]  Pointer to S
  36. ;-------------------------------------------------------------------------------
  37.  
  38. SDelete      PROC    FAR
  39.              PUSH    DS                ; save TURBO-Pascal data segment
  40.              MOV     BX, SP            ; make new framepointer
  41.              LES     CX, SS:[BX+6]     ; CX = count, ES = index
  42.              MOV     AX, ES            ; index
  43.              DEC     AX                ; index - 1
  44.              CWD                       ; DX = FFFFh if AX < 0 (else DX = 0)
  45.              AND     DX, AX            ; index ( else 0)
  46.              SUB     AX, DX            ; 0 (else index) = new index
  47.              ADD     DX, CX            ; index + count (else count) = new count
  48.              JLE     $end_del          ; exit, if new count <= 0
  49.              LDS     SI, SS:[BX+10]    ; address of string
  50.              MOV     CL, [SI]          ; length of string
  51.              XOR     CH, CH            ; clear msb of string length
  52.              SUB     CX, AX            ; length - index + 1
  53.              JLE     $end_del          ; exit, if <= 0,
  54.              SUB     CX, DX            ; length-count-index+1 = # chars to move
  55.              JG      $continue         ; continue, if # of chars > 0
  56.              MOV     [SI], AL          ; new length = index - 1
  57.              JMP     $end_del          ; done
  58. $continue:   CLD                       ; auto-increment
  59.              MOV     DI, DS            ; let both segment register
  60.              MOV     ES, DI            ;  hold segment of string
  61.              SUB     [SI], DL          ; new length = length - deleted chars
  62.              ADD     SI, AX            ; char at index
  63.              INC     SI                ;  becomes destination
  64.              MOV     DI, SI            ;   of move
  65.              ADD     SI, DX            ; char behind the last that will be del.
  66.              SHR     CX, 1             ; number of chars to move odd ?
  67.              JNC     $even_del         ; no
  68.              MOVSB                     ; yes, move single char
  69. $even_del:   REP     MOVSW             ; move the rest
  70. $end_del:    POP     DS                ; restore TURBO-Pascal data segment
  71.              RET     8                 ; return and pop parameters
  72. SDelete      ENDP
  73.  
  74.              ALIGN   4
  75.  
  76. CODE         ENDS
  77.  
  78.              END
  79.